// InCall.cpp : implementation file
//

#include "stdafx.h"
#include "rmsserver.h"
#include "InCall.h"
#include "resource.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CInCall dialog


CInCall::CInCall(CWnd* pParent, LPCTSTR title, LPCTSTR ip)
	: CMegaDialog(CInCall::IDD, pParent, IDB_INCOMING_CALL_BASE, IDB_INCOMING_CALL_BASE)
{
	m_Info = title;
	m_Ip=ip;
	if(m_Ip.IsEmpty()) m_Ip = "unknown";

	BOOL bRet = PlaySound(MAKEINTRESOURCE(IDR_RING), ::AfxGetInstanceHandle(),
						  SND_RESOURCE|SND_ASYNC|SND_LOOP|SND_NOSTOP);
}

BEGIN_MESSAGE_MAP(CInCall, CMegaDialog)
	//{{AFX_MSG_MAP(CInCall)
	ON_WM_TIMER()
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CInCall message handlers
void CInCall::OnOK() 
{
	// TODO: Add extra validation here
	EndDialog(IDOK);
}

void CInCall::OnCancel() 
{
	// TODO: Add extra cleanup here
	EndDialog(IDCANCEL);
}

void CInCall::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	//UpdateData(TRUE);
	TimerVal++;
	//m_Time.Format("%d",TimerVal);
	//UpdateData(FALSE);
	if (TimerVal>12) EndDialog(IDCANCEL);
	else CMegaDialog::OnTimer(nIDEvent);
}


BOOL CInCall::OnInitDialog() 
{
	CMegaDialog::OnInitDialog();

	SetTimer(1,1000,0);
	TimerVal=0;// 0 seconds

	
	// TODO: Add extra initialization here
	AdjustRegion();

	m_btnPickup.Create("", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, CRect(138, 163, 189, 184), this, IDOK);
	m_btnPickup.SetBitmaps(IDB_PICKUP_OUT, IDB_PICKUP_DOWN, IDB_PICKUP_OVER);
	m_btnPickup.SetBackgroundBmp(m_pSkinSingle);

	m_btnDecline.Create("", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, CRect(198, 163, 249, 184), this, IDCANCEL);
	m_btnDecline.SetBitmaps(IDB_DECLINE_OUT, IDB_DECLINE_DOWN, IDB_DECLINE_OVER);
	m_btnDecline.SetBackgroundBmp(m_pSkinSingle);

	m_btnAddCaller.Create("", WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX, CRect(18, 130, 31, 143), this, IDC_ADDCALLER);
	m_btnAddCaller.SetCheck(BST_CHECKED);


	m_stCaller.SetBitmap(IDB_ICON_CALL);
	m_stCaller.Create("", WS_CHILD|WS_VISIBLE, CRect(18, 51, 211, 72), this);
	m_stCaller.SetCaption(m_Info);
	m_stCaller.SetBackColor(RGB(235, 235, 242));

	m_stCallerIP.Create("", WS_CHILD|WS_VISIBLE, CRect(18, 100, 114, 117), this);
	m_stCallerIP.SetCaption(m_Ip);
	m_stCallerIP.SetBackColor(RGB(235, 235, 242));

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CInCall::OnDestroy() 
{
	KillTimer(1);
	PlaySound(0, ::AfxGetInstanceHandle(),0);
	CMegaDialog::OnDestroy();	
	// TODO: Add your message handler code here	
	m_AddCaller = (m_btnAddCaller.GetCheck() == BST_CHECKED);
}
